const { adminsModel } = require('./models/adminsModel')


module.exports.getAdmins = async ({ _id, username }) => {
    // console.log(username);
    try {
        let data = [];
        if (_id) {
            data = await adminsModel.find({ _id, isDel: false });
        } else if (username) {
            data = await adminsModel.find({ username, isDel: false });
        } else {
            data = await adminsModel.find({ isDel: false });
        }
        return { data }
    } catch (error) {
        return { error }
    }

}

//通过id去修改
module.exports.modifyAdmins = async ({ _id, update }) => {
    // console.log(_id, update, 980);
    try {
        const data = await adminsModel.updateOne({ _id }, update)
        return { data }
    } catch (error) {
        return { error }
    }
}


//delAdmins
module.exports.delAdmins = async params => {
    // console.log(params, '121');
    return await adminsModel.updateOne(params, { isDel: true });
}
//changeState
module.exports.changeState = async params => {
    // console.log(params, '121');
    return await adminsModel.updateOne(params, { isAdmins: false });
}

module.exports.addAdmins = async params => {
    return await adminsModel.create(params)
}


//新增是否有重合的
// module.exports.isexist = async parms => {
//     // console.log(234, parms.stunum );
//     const data = await adminsModel.find({ stunum: parms.stunum })
//     // console.log('000',data);
//     return data;

// }

// //新增添加到数据库
// module.exports.addAdmins = async parms => {
//     const data = await studentsModel.create(parms);
//     return data;
//     // console.log('333',data);
// }
